package com.qztc.controller;

import com.qztc.hire_end_dto.dto.ForumType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

import static com.qztc.config.GlobalConfig.SERVICE_URL;

@RestController
@RequestMapping("/consumer/forumType")
@Tag(name = "消费者端论坛类型管理接口")
public class ForumTypeConrollerByRestTemplate {
    @Autowired
    private RestTemplate restTemplate;

    @Operation(summary = "查询所有论坛类型")
    @GetMapping("/getAll")
    public String getAll() {
        return restTemplate.getForObject(SERVICE_URL+"/forumType/getAll", String.class);
    }

    @Operation(summary = "获取具体论坛类型")
    @GetMapping("/getbyforumTypeId")
    public String getbyforumTypeId(@RequestParam Integer forumTypeId) {
        return restTemplate.getForObject(SERVICE_URL+"/forumType/getbyforumTypeId?forumTypeId="+forumTypeId, String.class);
    }

    @Operation(summary = "增加论坛类型")
    @PostMapping("/add")
    public String add(@RequestBody ForumType forumType) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<ForumType> entity = new HttpEntity<>(forumType, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/forumType/add", HttpMethod.POST,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "删除论坛类型")
    @DeleteMapping("/delete")
    public String delete(@RequestBody ForumType forumType) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<ForumType> entity = new HttpEntity<>(forumType, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/forumType/delete", HttpMethod.DELETE,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "修改论坛类型")
    @PutMapping("/update")
    public String update(@RequestBody ForumType forumType) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<ForumType> entity = new HttpEntity<>(forumType, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/forumType/update", HttpMethod.PUT,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "批量删除论坛类型")
    @DeleteMapping("/deleteMany")
    public String deleteMany(@RequestBody List<Integer> forumTypeIds) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<List<Integer>> entity = new HttpEntity<>(forumTypeIds, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/forumType/deleteMany", HttpMethod.DELETE,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "批量增加论坛类型")
    @PostMapping("/addMany")
    public String addMany(@RequestBody List<ForumType> forumTypes) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<List<ForumType>> entity = new HttpEntity<>(forumTypes, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/forumType/addMany", HttpMethod.POST,entity, String.class);
        return result.getBody();
    }
}
